/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package SYSGEST.br.Funcionarios;

import sysgest.conexao.HibernateUtil;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author AELSON
 */
public class FuncionarioDAO {

    private Session sessao;
    private Transaction transacao;

    public void salvar(Funcionario funcionario) {
        try {
            sessao = HibernateUtil.getSessionFactory()
                    .openSession();
            transacao = sessao.beginTransaction();
            sessao.save(funcionario);
            transacao.commit();
        } catch (Exception e) {
            System.out.println("Erro ao salvar o registro");
        } finally {
            sessao.close();
        }
    }

    public void deletar(Funcionario funcionario) {
        try {
            sessao = HibernateUtil.getSessionFactory()
                    .openSession();
            transacao = sessao.beginTransaction();
            sessao.delete(funcionario);
            transacao.commit();

        } catch (Exception e) {
            System.out.println("Erro ao deletar o registro");
        } finally {
            sessao.close();
        }

    }
}
